package easymall.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import easymall.Utils.MailUtil;

@Controller
public class EmailController {
	@RequestMapping("/sendcode")
	public void AjaxSendIdCode(String mail, HttpServletResponse response,HttpServletRequest request) 
            throws IOException, AddressException, MessagingException{
	PrintWriter out = response.getWriter();
	response.setCharacterEncoding("utf-8");
	int idcode = (int) (Math.random()*100000);
	String text = "您的验证码为： "+Integer.toString(idcode);

	request.getSession().setAttribute("idcode", idcode+"");
	MailUtil mailUtil = new MailUtil();	
	mailUtil.sendMail(mail, text);
}
}
